package com.zzg.datastructure.linkedlist;

/**
 * @Author zhengzg
 * @Date 2022-08-16
 * @Version v1.0
 */
public class LinkedListDemo {

    public static void main(String[] args) {
        // 创建节点
        HeroNode node1 = new HeroNode(1, "宋江", "及时雨");
        HeroNode node2 = new HeroNode(2, "卢俊义", "玉麒麟");
        HeroNode node3 = new HeroNode(3, "吴用", "智多星");
        HeroNode node4 = new HeroNode(4, "林冲", "豹子头");

        // 创建链表
        SingleLinkedList singleLinkedList = new SingleLinkedList();

        // 直接添加
//        singleLinkedList.add(node1);
//        singleLinkedList.add(node2);
//        singleLinkedList.add(node3);
//        singleLinkedList.add(node4);

        // 按照编号顺序添加
        singleLinkedList.addByOrder(node1);
        singleLinkedList.addByOrder(node4);
        singleLinkedList.addByOrder(node3);
        singleLinkedList.addByOrder(node2);

        // 显示
        singleLinkedList.list();

        // 删除
        singleLinkedList.del(2);

        // 修改
        singleLinkedList.update(new HeroNode(3, "吴用", "智少星"));

        // 展示
        singleLinkedList.list();

        // 单链表的面试题
        // 获取头节点
        HeroNode head = singleLinkedList.getHead();

        // 新浪面试题
        HeroNode heroNode = SingleLinkedList.findLastIndexNode(head, 3);
        System.out.println(heroNode);

        System.out.println("=======================================================");

        // 腾讯面试题
        SingleLinkedList.reversetList(head);
        singleLinkedList.list();

        System.out.println("=======================================================");

        // 百度面试题
        SingleLinkedList.reversetPrint(head);

    }
}
